<template>
  <yt-page title="隐患详情" scroll>
    <yt-card title="基础信息">
      <yt-cell label="企业名称" :value="item.enterprise_name ? item.enterprise_name.attributes.EnterpriseName : ''"></yt-cell>
      <yt-cell label="检查时间" :value="item.check_time"></yt-cell>
      <yt-cell label="检查人" :value="item.check_person"></yt-cell>
      <yt-cell label="层级" :value="getListLevelVal(item.list_level)"></yt-cell>
      <yt-cell label="隐患级别" :value="getLevel(item.Hidden_danger_level)"></yt-cell>
      <yt-cell label="隐患类别" :value="getDangerTypeVal(item.danger_type)"></yt-cell>
      <yt-textarea disabled title="隐患内容" v-model="item.text" border="half"></yt-textarea>
    </yt-card>
    <yt-card title="其他信息">
      <yt-cell label="整改部门" :value="item.rectificationDepartment"></yt-cell>
      <yt-cell label="整改负责人" :value="item.rectificationPersonInCharge"></yt-cell>
      <yt-cell label="限期整改时间" labelWidth="150px" :value="item.deadlineForRectification"></yt-cell>
      <yt-cell label="整改前照片"></yt-cell>
      <yt-file v-model="item.files" :uploadFile="uploadFile" :disabled="true"></yt-file>
    </yt-card>
  </yt-page>
</template>

<script>
import { commonApi } from '@/common/api/commonApi.js'
const LEVEL = [
  {
    D_text: '一般隐患',
    D_code: 1
  },
  {
    D_text: '重大隐患',
    D_code: 2
  }
]
const STATE = {
  1: '未整改',
  3: '已整改'
}
export default {
  data() {
    return {
      STATE,
      level: LEVEL,
      item: {},
      listLevelDic: [],
      dangerTypeDic: [],
      uploadFile: () => {}
    }
  },
  activated() {
    this.getData()
  },
  methods: {
    async getData() {
      let [dic, dic2] = await commonApi.dictionaries([
        'hierarchy',
        'danger_hidden'
      ])
      this.item = this.$route.params

      this.listLevelDic = dic
      this.dangerTypeDic = dic2
    },
    getLevel(level) {
      if (!level) return
      let item = this.level.filter(item => {
        return item.D_code === level
      })
      return item.D_text
    },
    getListLevelVal(listLevel) {
      if (!this.listLevelDic.length) return
      let item = this.listLevelDic.filter(item => {
        return item.D_code === listLevel
      })
      return item.D_text
    },
    getDangerTypeVal(dangerType) {
      if (!this.dangerTypeDic.length) return
      let item = this.dangerTypeDic.filter(item => {
        return item.D_code === dangerType
      })
      return item.D_text
    },
    handlerTap(file) {
      if (!file.url) {
        Toast('文件不存在', 'tool')
      } else if (isImg(file.name)) {
        PreviewImg({ current: 0, list: [file.url] })
      } else if (isVideo(file.name)) {
        PreviewVideo({
          current: 0,
          list: [{ title: file.name, url: file.url }]
        })
      } else {
        bridge.PreviewFile({ title: file.name, url: file.url })
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
.flex
  display flex
  justify-content space-between
  align-items center
  padding 10px
  background-color #fff

.flex img
  width 23%
  height 50px
</style>
